﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Persistence;
using Persistence.Dao;
using Domain;
using System.Collections.Generic;
namespace web
{
    public partial class _Default : System.Web.UI.Page
    {
        protected List<OrderDetailMen> menlist = new List<OrderDetailMen>();
        protected List<OrderDetailKou> koulist = new List<OrderDetailKou>();
        protected List<OrderDetailOther> otherlist = new List<OrderDetailOther>();

        private void GetStoreDetail()
        {
            if (Session["OrderDetailMen"] != null)
                menlist = (List<OrderDetailMen>)Session["OrderDetailMen"];
            if (Session["OrderDetailKou"] != null)
                koulist = (List<OrderDetailKou>)Session["OrderDetailKou"];
            if (Session["OrderDetailOther"] != null)
                otherlist = (List<OrderDetailOther>)Session["OrderDetailOther"];
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            GetStoreDetail();
            bindSendMessage();
            bindProduct();
            bindAD();
            if (!IsPostBack)
            {
                BindTitle(1, titleRepeater,6);
                BindTitle(2, Repeater1, 6);
                BindTitle(3, Repeater2, 6);

                BindTitle(0, Repeater3, 3);
                Repeater4.DataSource = Singleton<NewsDao>.Instance.GetModels("*", "(newstype=1 or newstype=2 or newstype=3) ", "newsid desc", 10, 1);
                Repeater4.DataBind();


            }
        }
        //登陆
        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Domain.User user = Singleton<UserDao>.Instance.GetModelWhenLogin(username.Value.Trim(), password.Value.Trim());
            if (user != null)
            {
                Session["user"] = user;
                Response.Redirect("/default.aspx");
            }
        }
        private void BindTitle(int type ,Repeater rpt,int top)
        {
            rpt.DataSource = Singleton<NewsDao>.Instance.GetModels("*", "newstype=" + type, "newsid desc", top, 1);
            rpt.DataBind();
        }
        /// <summary>
        /// 绑定发货信息
        /// </summary>
        private void bindSendMessage()
        {
            //rptSendMessage.DataSource = Singleton<SendMessageDao>.Instance.GetModels("*", "1=1", " id desc", 8, 1);
            //rptSendMessage.DataBind();
        }
        /// <summary>
        /// 绑定产品
        /// </summary>
        private void bindProduct()
        {
            repProductList.DataSource = new ProductDao().GetModels("*", "1=1", "productIndexOrder asc", 12, 1);
            repProductList.DataBind();
        }

        private void bindAD()
        {
            rptAD.DataSource = Singleton<FlashADDao>.Instance.GetModels("*", "1=1", "adorder asc", 10, 1);
            rptAD.DataBind();
        }
    }
}
